import 'dart:async';

import 'package:flutter/material.dart';
import 'package:umeng_analytics_plugin/umeng_analytics_plugin.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  Future<void> initPlatformState() async {
    var result = await UmengAnalyticsPlugin.init(
      androidKey: '605174656ee47d382b872579',
      iosKey: '6051749fb8c8d45c13a0f6a0',
      logEnabled: true,
    );

    print('Umeng initialized.');

    if (!mounted) {
      return;
    }

    setState(() {
      _platformVersion = result ? 'OK' : 'ERROR';
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            children: [
              Text('Running on: $_platformVersion\n'),
              OutlinedButton(
                  onPressed: () {
                    UmengAnalyticsPlugin.event("test11");
                  },
                  child: Text("测试事件")),
              OutlinedButton(
                onPressed: () {
                  UmengAnalyticsPlugin.event("test2", label: {
                    "value": "sdad",
                  });
                },
                child: Text("测试事件2"),
              ),
              OutlinedButton(
                onPressed: () {
                  UmengAnalyticsPlugin.error("上报Error");
                },
                child: Text("上报Error"),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
